package ServletsPackage;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import DAOPackage.ConnectionManager;
import DAOPackage.DAOManagement;
import ModelsPackage.CourseBean;

/**
 * Servlet implementation class LoginServlet
 */
@WebServlet("/ChangeCourseLanguage")
public class ChangeCourseLanguage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChangeCourseLanguage() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Connection currentCon = null;
		try
        {
			  
            System.out.println("In the ChangeCourseLanguage Servlet");
            int courseID = Integer.parseInt(request.getParameter("courseID"));
            String newLanguage = request.getParameter("changeLanguage");
            System.out.println("Language: " + newLanguage + ", courseID:" + courseID);
            
			int result = DAOManagement.updateCourseLanguage(newLanguage, courseID);
			if(result==0)
            	System.out.println("DB Error!");
            CourseBean course = new CourseBean();
            course = DAOManagement.getCourseInformation(courseID);
            /*
            request.setAttribute("course", course);
            RequestDispatcher rd = request.getRequestDispatcher("displayCourse.jsp");
            rd.forward(request, response);
            */
            response.sendRedirect("DisplayServlet?courseID="+courseID);
            
        }
		catch (Throwable exc)
        {
            System.out.println(exc);
        }	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
